package net.knightwatch.kwtools.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DatabaseHelper extends SQLiteOpenHelper {
	// File used for creation, upgrade and version management of the database.
	// Database name and version
	private static final String DATABASE_NAME = "kwtools.db";
	private static final int DATABASE_VERSION = 13;
	private static final String TAG = "DatabaseHelper";
	

	public DatabaseHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}
	
	@Override
	public void onCreate(SQLiteDatabase database) {
		// Create methods for all tables
		AddressTable.onCreate(database);
		AnswerTable.onCreate(database);
		AnswerTypeTable.onCreate(database);
		AutoCompleteAnswersTable.onCreate(database);
		AutoCompleteQuestionTable.onCreate(database);
		BooleanAnswersTable.onCreate(database);
		BooleanQuestionTable.onCreate(database);
		BuildingTable.onCreate(database);
		CustomerTable.onCreate(database);
		ItemTable.onCreate(database);
		ItemTypeTable.onCreate(database);
		PhotoAnswerTable.onCreate(database);
		PhotoQuestionTable.onCreate(database);
		PotentialTable.onCreate(database);
		QuestionTable.onCreate(database);
		RadioButtonAnswersTable.onCreate(database);
		RadioButtonQuestionTable.onCreate(database);
		SpinnerAnswersTable.onCreate(database);
		SpinnerQuestionTable.onCreate(database);
		TextAnswersTable.onCreate(database);
		TextQuestionTable.onCreate(database);
		}

	@Override
	public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
		// Upgrade Methods for all tables
		Log.d(TAG, "Database upgrading... From: "+ oldVersion + " To: " + newVersion);
		AddressTable.onUpgrade(database, oldVersion, newVersion);
		AnswerTable.onUpgrade(database, oldVersion, newVersion);
		AnswerTypeTable.onUpgrade(database, oldVersion, newVersion);
		AutoCompleteAnswersTable.onUpgrade(database, oldVersion, newVersion);
		AutoCompleteQuestionTable.onUpgrade(database, oldVersion, newVersion);
		BooleanAnswersTable.onUpgrade(database, oldVersion, newVersion);
		BooleanQuestionTable.onUpgrade(database, oldVersion, newVersion);
		BuildingTable.onUpgrade(database, oldVersion, newVersion);
		CustomerTable.onUpgrade(database, oldVersion, newVersion);
		ItemTable.onUpgrade(database, oldVersion, newVersion);
		ItemTypeTable.onUpgrade(database, oldVersion, newVersion);
		PhotoAnswerTable.onUpgrade(database, oldVersion, newVersion);
		PhotoQuestionTable.onUpgrade(database, oldVersion, newVersion);
		PotentialTable.onUpgrade(database, oldVersion, newVersion);
		QuestionTable.onUpgrade(database, oldVersion, newVersion);
		RadioButtonAnswersTable.onUpgrade(database, oldVersion, newVersion);
		RadioButtonQuestionTable.onUpgrade(database, oldVersion, newVersion);
		SpinnerAnswersTable.onUpgrade(database, oldVersion, newVersion);
		SpinnerQuestionTable.onUpgrade(database, oldVersion, newVersion);
		TextAnswersTable.onUpgrade(database, oldVersion, newVersion);
		TextQuestionTable.onUpgrade(database, oldVersion, newVersion);
	}
}
